package com.tonyodev.fetch2.downloader;

import com.tonyodev.fetch2.Download;
import com.tonyodev.fetch2.Error;
import com.tonyodev.fetch2.database.DownloadInfo;
import com.tonyodev.fetch2core.DownloadBlock;

import java.util.List;

/**
 * @since 2021-05-20
 */
public interface FileDownloader extends Runnable{

    boolean getInterrupted();
    void setInterrupted(boolean interrupted);
    boolean getTerminated();
    void setTerminated(boolean terminated);
    boolean getCompletedDownload();
    Delegate getDelegate();
    void setDelegate(Delegate delegate);
    Download getDownload();

    
    interface Delegate{
        boolean getInterrupted();

        void onStarted(Download download, List<DownloadBlock> downloadBlocks, int totalBlocks);

        void onDownloadBlockUpdated(Download download, DownloadBlock downloadBlock, int totalBlocks);

        void onProgress(Download download, long etaInMilliSeconds, long downloadedBytesPerSecond);

        void onError(Download download, Error error, Throwable throwable);

        void onComplete(Download download);

        void saveDownloadProgress(Download download);

        DownloadInfo getNewDownloadInfoInstance();
    }
}
